package com.controller;

import com.dto.BorrowBookDTO;
import com.service.LoginServiceImpl;
import com.service.StatisticsServiceImpl;
import com.util.Result;
import com.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 统计相关的接口
 * @author linyukun
 * @date 2022/10/14 11:01
 */
@RequestMapping("statistics")
@RestController
public class StatisticsController {
    @Autowired
    private LoginServiceImpl loginServiceImpl;

    @Autowired
    private StatisticsServiceImpl statisticsServiceImpl;

    /**
     * 获取一些统计数据
     * @author linyukun
     * @date 2022-10-14
     */
    @RequestMapping(value="/getStatistics",method = RequestMethod.POST)
    public Result getStatistics(@RequestBody BorrowBookDTO dto){
        try{
            loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess( statisticsServiceImpl.getStatistics(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }
}
